<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <style>
      body {
        font-size: 30px;
      }
      .btn {
        padding: 10px 20px;
        font-size: 20px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="to('A')">A</button> <button @click="to('B')">B</button>
      <button @click="to('C')">C</button>

      <keep-alive>
        <component v-bind:is="currentTabComponent"></component>
      </keep-alive>
     
    </div>

    <script>
      var A = Vue.extend({
        template: "<div>AAAAAAAAAAAAAAAA</div>",
        data: function() {
          return {};
        },
        created:function(){
          console.log("a");
        }
      });

      var B = Vue.extend({
        template: "<div>BBBBBBBBBBBBBBBBBBBBBBB</div>",
        data: function() {
          return {};
        },
        created:function(){
          console.log("b");
        }
      });

      var C = Vue.extend({
        template: "<div>CCCCCCCCCCCCCCCCCCCCCCC</div>",
        data: function() {
          return {};
        },
        
        created:function(){
          console.log("c");
        }
      });

      // 创建根实例
      new Vue({
        el: "#app",
        data: {
          currentTabComponent: "A"
        },
        methods: {
          to: function(to) {
            this.currentTabComponent = to;
          }
        },
        components: {
          A,
          B,
          C
        }
      });
    </script>
  </body>
</html>
